package com.hellloop.pim.alphabeat.network;

import java.util.StringTokenizer;

public class PIMConnectionMsg extends PIMMessage{	
	//<Username>:<Password>
	public static int RequestLogin= 1;
	//<UserId>
	public static int LoginResponse= 2;
	//<UserId>
	public static int Disconnect = 3;
	
	String _userName;
	String _passWord;
	String _userId;
	
	public PIMConnectionMsg() {
		_msgType = MsgType.ConnectionMsg;
		_userName = "";
		_passWord = "";
		_userId = "";
	}
	public PIMConnectionMsg(int oprType, String message) {
		_msgType = MsgType.ConnectionMsg;
		_oprType = oprType;
		
		StringTokenizer st = new StringTokenizer(message, ":");
		try {			
			if( _oprType == PIMConnectionMsg.RequestLogin) {
				_userName = st.nextToken();
				_passWord = st.nextToken();
			}
			else if( _oprType == PIMConnectionMsg.LoginResponse ) {
				_userId = st.nextToken();
				_userName = st.nextToken();
			}
		}
		catch(Exception e) {
			System.err.println("Error PIMMessage Format-PIMConnectionMsg");
			_message = message;
		}
	}
	
	public String toString() {
		StringBuffer buff = new StringBuffer();
		buff.append( getMsgType() ).append(":");
		buff.append( getOprType() ).append(":");
		if( _oprType == PIMConnectionMsg.RequestLogin) {
			buff.append( _userName ).append(":");
			buff.append( _passWord );
		}
		else if( _oprType == PIMConnectionMsg.LoginResponse ) {
			buff.append( _userId ).append(":");
			buff.append( _userName );
		}
		
		return buff.toString();
	}
	
	public String getUserName() {
		return _userName;
	}
	public String getPassword() {
		return _passWord;
	}
	public String getUserId() {
		return _userId;
	}
	public void setUserName(String userName) {
		_userName = userName;
		setMessage(userName);
	}
	public void setPassWord(String passWord) {
		_passWord = passWord;
		setMessage(passWord);
	}
	public void setUserId(String userId) {
		_userId = userId;
		setMessage(userId);
	}
	
}
